package edu.westga.cs3152.wordmojo;

import java.util.ArrayList;

/**
 * The SpellChecker takes in an array list of words
 * and checks to see if they are spelled correctly
 * and fit the rules of the game..
 * 
 * @author Lewis Williams
 * @version 2011.3.18
 */
public class SpellChecker {

	// The dictionary to compare words against
	private Dictionary dictionary = new Dictionary("words.txt");
	private int lengthOfAllWords = 0;

	/**
	 * A default constructor for Dictionary that does nothing.
	 */
	public SpellChecker() {
		dictionary.returnThreeLetterWord();
		dictionary.returnFourLetterWord();
	}

	/**
	 * Finds misspelled or wrongly played words.
	 */
	public int checkSpelling(ArrayList<String> words) {
		String currentWord = "";		
		int result = 0;
		currentWord = "";
		for(int i = 0 ; i < words.size(); i++) {
			currentWord = words.get(i);
			// Makes the current word lower case
			currentWord = currentWord.toLowerCase();
			// to the misspelled word list
			if (!dictionary.contains(currentWord) && !currentWord.equalsIgnoreCase("") && currentWord.length() > 2) {
				result = -1;
				return result;
			}
			else if(currentWord.length() < 3){
				result = 0;
				return result;
			}
			else{
				result += currentWord.length();
				lengthOfAllWords += currentWord.length();
			}
		}
		return result;
	}
	
	public int getLengthOfAllWords() {
		return lengthOfAllWords;
	}

	public void setLengthOfAllWords(int lengthOfAllWords) {
		this.lengthOfAllWords = lengthOfAllWords;
	}

}